<template>
  <div>
    <el-table style="width: 100%" :data="records">
      <el-table-column type="index" label="序号" align="center" width="80">
      </el-table-column>
      <el-table-column prop="skuName" label="名称" width="width">
      </el-table-column
      ><el-table-column prop="skuDesc" label="描述" width="width">
      </el-table-column
      ><el-table-column label="默认图片" width="110">
        <template slot-scope="{ row }">
          <img
            :src="row.skuDefaultImg"
            alt=""
            style="width: 80px; height: 80px"
          />
        </template> </el-table-column
      ><el-table-column prop="weight" label="重量" width="80"> </el-table-column
      ><el-table-column prop="prce" label="价格（元）" width="100">
      </el-table-column
      ><el-table-column label="操作" width="width">
        <template slot-scope="{ row }">
          <!-- 下架 -->
          <el-tooltip
            v-if="row.isSale == 1"
            effect="dark"
            content="下架"
            placement="top"
          >
            <el-button
              type="success"
              icon="el-icon-bottom"
              size="mini"
              @click="cancel(row)"
            ></el-button>
          </el-tooltip>
          <!-- 上架 -->
          <el-tooltip v-else effect="dark" content="上架" placement="top">
            <el-button
              type="success"
              icon="el-icon-top"
              size="mini"
              @click="sale(row)"
            ></el-button>
          </el-tooltip>
          <!-- 修改 -->
          <el-tooltip effect="dark" content="修改" placement="top">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="edit"
            ></el-button>
          </el-tooltip>
          <!-- 详情 -->
          <el-tooltip effect="dark" content="sku详情" placement="top">
            <el-button
              type="info"
              icon="el-icon-info"
              size="mini"
              @click="getSkuInfo(row)"
            ></el-button>
          </el-tooltip>
          <!-- 删除 -->
          <el-tooltip effect="dark" content="删除" placement="top">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
            ></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      style="text-align: center"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[5, 10, 15]"
      :page-size="limit"
      layout=" prev, pager, next, jumper,->, sizes,total"
      :total="total"
    >
    </el-pagination>
    <!-- 抽屉 -->
    <el-drawer title="我是标题" :visible.sync="show" size="50%">
      <el-row :gutter="10">
        <el-col :span="6">名称</el-col>
        <el-col :span="15">{{ skuInfo.skuName }}</el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="6">描述</el-col>
        <el-col :span="15">{{ skuInfo.skuDesc }}</el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="6">价格</el-col>
        <el-col :span="15">{{ skuInfo.price }}</el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="6">平台属性</el-col>
        <el-col :span="15">
          <template>
            <el-tag
              type="success"
              v-for="skuAttr in skuInfo.skuAttrValueList"
              :key="skuAttr.id"
              >{{ skuAttr.attrName }}--{{ skuAttr.valueName }}</el-tag
            >
          </template>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="6">商品图片</el-col>
        <el-col :span="15">
          <el-carousel height="450px" style="width:450px">
            <el-carousel-item v-for="item in skuInfo.skuImageList" :key="item.id">
              <img :src="item.imgUrl">
            </el-carousel-item>
          </el-carousel>
        </el-col>
      </el-row>
    </el-drawer>
  </div>
</template>

<script>
export default {
  name: 'Sku',
  data() {
    return {
      //分页
      page: 1,
      limit: 3,
      total: 0,
      //存储SKU列表的数据
      records: [],
      //sku详情信息
      skuInfo: {},
      //sku详情抽屉的xianshi
      show: false
    }
  },
  mounted() {
    this.getSkuList()
  },
  methods: {
    handleSizeChange(limit) {
      this.limit = limit
      this.getSkuList()
    },
    handleCurrentChange(page) {
      this.page = page
      this.getSkuList()
    },
    async getSkuList() {
      const { page, limit } = this
      let result = await this.$API.sku.reqSkuList(page, limit)
      if (result.code == 200) {
        this.total = result.data.total
        this.records = result.data.records
      }
    },
    //上架
    async sale(row) {
      let result = await this.$API.sku.reqSale(row.id)
      if (result.code == 200) {
        row.isSale = 1
        this.$message.success('上架成功')
      }
    },
    //下架
    async cancel(row) {
      let result = await this.$API.sku.reqCancel(row.id)
      if (result.code == 200) {
        row.isSale = 0
        this.$message.success('下架成功')
      }
    },
    edit() {
      this.$message.info('正在开发中...')
    },
    //获取SkuInfo
    async getSkuInfo(sku) {
      //显示
      this.show = true
      //获取SKU数据
      let result = await this.$API.sku.reqSkuById(sku.id)
      if (result.code == 200) {
        this.skuInfo = result.data
      }
    },
    //删除Sku
    deletesku() {}
  }
}
</script>

<style scoped>
.el-row .el-col-5 {
  font-size: 18px;
  text-align: right;
}
.el-col {
  margin: 10px 10px;
}

>>> .el-carousel__button {
  width: 10px;
  height: 10px;
  background: red;
  border-radius: 50%;
}

.el-carousel__item img {
    width: 500px;
    height: 450px;
  }

  .el-carousel__item:nth-child(2n) {
     background-color: #99a9bf;
  }
  
  .el-carousel__item:nth-child(2n+1) {
     background-color: #d3dce6;
  }
</style>
